#include "com.h"

int main()
{
  //生成key值
  key_t key = ftok(PATH_NAME, PROJ_ID); 
  if(key == -1){
    perror("ftok");
    exit(1);
  }

  //创建共享内存
  int shmid =  shmget(key, SIZE, IPC_CREAT | IPC_EXCL | 0644);
  if(shmid < 0){
    perror("shmget");
    exit(2);
  }

  char* shmaddr = shmat(shmid, NULL, 0);
  for(int i = 200; i > 0; i--){
    sleep(1);
    printf("client msg# %s\n", shmaddr);
  }

  //取消联系
  shmdt(shmaddr);
  
  //释放共享内存
  if(shmctl(shmid, IPC_RMID, NULL) < 0){
    perror("shmctl");
    exit(3);
  }

  return 0;
}
